<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<div id="host"><b id="one" slot="one">one</b><b id="two" slot="two">two</b></div>
<div id="log"></div>
<script>
var host = document.querySelector('#host');
var shadowRoot = host.attachShadow({mode: 'open'});
shadowRoot.innerHTML = 'A<slot name="two"></slot>B C<slot name="one"></slot>D';
var two = document.querySelector('#two');
test(function() {
    if (!window.eventSender || window.internals)
        return;
    eventSender.mouseMoveTo(two.offsetLeft + 3, two.offsetTop + 3);
    eventSender.mouseDown();
    eventSender.mouseUp();
    eventSender.mouseDown();
    eventSender.mouseUp();

    // TODO(yosin) Once Selection API consider about flat tree, we should
    // use Selection.{anchor,focus}{Node,Offset} to check selection boundary
    // point.
    assert_equals(internals.selectedTextForClipboard(), 'AtwoB');

    // TODO(yosin) Once Selection API supports flat tree, we should change
    // these values.
    var selection = shadowRoot.getSelection();
    assert_equals(selection.anchorNode(), 'two');
    assert_equals(selection.anchorNode(), 1);
    assert_equals(selection.focusNode(), 'two');
    assert_equals(selection.focusNode(), 1);
}, 'Double-click in shadow tree');
</script>
